<!-- this.$store.state.userId -->
<!-- Calendar.vue -->
<template>
	<view class="calendar">
		<uni-calendar v-if="showCalendar" class="uni-calendar--hook" lunar :selected="selected" :showMonth="false"
			@change="changeEvent" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showCalendar: false,
				selected: []
			};
		},
		computed: {},
		methods: {
			getSignLog() {
				this.$api.request({
					url: this.$api.signLog,
				}).then(res => {
					this.selected = res.data.map(item => {
						return {
							date: uni.$u.timeFormat(Date.parse(item.createTime), 'yyyy-mm-dd'),
							info: "已打卡"
						};
					});
					this.$nextTick(() => {
						this.showCalendar = true
					})
				})
			},
			// getRecordList(time) {
			// 	console.log(time);
			// 	this.$api.request({
			// 		url: this.$api.getUserRecordList,
			// 		data: {
			// 			userId: this.$store.state.userId, // 查询当前用户id
			// 			createTimeStr: time ? time : '' // 日期
			// 		}
			// 	}).then(res => {
			// 		this.selected = res.rows.map(item => {
			// 			return {
			// 				date: uni.$u.timeFormat(Date.parse(item.createTime), 'yyyy-mm-dd'),
			// 				info: "已打卡"
			// 			};
			// 		});
			// 		this.$nextTick(() => {
			// 			this.showCalendar = true
			// 		})
			// 	})
			// },
			changeEvent(e) {
				console.log(e.fulldate);
				// this.getRecordList(e.fulldate)
			},
		},
		mounted() {
			this.getSignLog();
			// this.getRecordList();
		},
	};
</script>

<style scoped>
	.calendar {
		padding: 10px;
	}

	.calendar-header {
		text-align: center;
		font-size: 20px;
		margin-bottom: 10px;
	}

	.calendar-body {
		display: grid;
		grid-template-columns: repeat(7, 1fr);
		gap: 5px;
	}

	.calendar-row {
		display: contents;
	}

	.calendar-cell {
		width: 30px;
		height: 30px;
		text-align: center;
		line-height: 30px;
		border: 1px solid #ddd;
		border-radius: 5px;
	}

	.today {
		background-color: #ffeb3b;
	}
</style>